#include "myhttpd.h"
#include "list_client.h"

s_client *init_client(int socket)
{
  s_client *client = NULL;

  client = malloc(sizeof (s_client));
  if (client != NULL)
    client->socket = socket;

  return (client);
}

void add_client(s_client **list, s_client *client)
{
  if (client != NULL)
  {
    client->next = *list;
    *list = client;
  }
}

void delete_client(s_client **list, s_client *client)
{
  s_client *save	= *list;
  s_client *prec	= *list;

  if (*list != NULL)
  {
      while (*list != NULL && *list != client)
      {
	prec = *list;
	*list = (*list)->next;
      }
      if (*list != NULL)
      {
	prec->next = (*list)->next;
	free(*list);
	*list = NULL;
      }
      if (*list != NULL && save != client)
	*list = save;
  }
}


